package com.example.barcodeapp.adapter.gatheradapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.barcodeapp.R;
import com.example.barcodeapp.common.Constants;
import com.example.barcodeapp.ui.home.AdapterRili;
import com.example.barcodeapp.ui.home.bean.JiaoShiLeiBiaoBean;

import java.util.ArrayList;
import java.util.List;

//   return R.layout.adapter_kecheng;
public class AdapterJiangShi extends RecyclerView.Adapter<AdapterJiangShi.ViewHolder> {

    Context context;
    private List<JiaoShiLeiBiaoBean.DataEntity.TeacherEntity> list;
    private AdapterJiangShi.IClick callback;

    public void setClick(AdapterJiangShi.IClick cb) {
        callback = cb;
    }
    public AdapterJiangShi(Context context, List<JiaoShiLeiBiaoBean.DataEntity.TeacherEntity> list) {
        this.context = context;
        this.list = list;
    }

    public AdapterJiangShi(Context context) {
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.adapter_kecheng, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
//jiangshi_imageView2
        Glide.with(context).load(Constants.Base_TPUrl2 +list.get(position).getImage()).into(holder.jiangshiImageView2);
        holder.nameJiangshi.setText(list.get(position).getName());
        holder.leibieText.setText(list.get(position).getCoursecate());
        Log.e("asdawdasdawd", "onBindViewHolder: "+list.get(position).getCoursecate() );
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                callback.click(position);
            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }



    public class ViewHolder extends RecyclerView.ViewHolder {

        private ImageView jiangshiImageView2;
        private TextView leibieText;
        private TextView nameJiangshi;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            jiangshiImageView2 = (ImageView)itemView.findViewById(R.id.jiangshi_imageView2);
            leibieText = (TextView) itemView.findViewById(R.id.leibie_text);
            nameJiangshi = (TextView) itemView.findViewById(R.id.name_jiangshi);
        }
    }

    public interface IClick {

        void click(int pos);

    }
}
